//
//  CollectionViewFlowLayout.swift
//  CooperSwift
//
//  Created by 计海峰 on 2021/6/11.
//

import Foundation

import class UIKit.UICollectionViewLayout


public extension UICollectionViewFlowLayout {
    
     func defaultLayout(lineNum num: Int = 3, minimumLineSpacing lineSpace: CGFloat = 8.0, minimumInteritemSpacing interitemSpace: CGFloat = 8.0, sectionInset inset: UIEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)) -> Self {
        
        let horizontalNum = num > 0 ? CGFloat(num) : 3.0
        let horizontalSpace = (horizontalNum - 1) * lineSpace
        let cellWidth = (Screen.width - horizontalSpace - inset.left - inset.right) / horizontalNum - 0.01
        
        headerReferenceSize = .zero
        footerReferenceSize = .zero
        minimumLineSpacing = lineSpace
        minimumInteritemSpacing = interitemSpace
        sectionInset = inset
        scrollDirection = .vertical
        itemSize = CGSize(cellWidth, cellWidth)
        
//        let layout = UICollectionViewFlowLayout.init().then{
//            $0.headerReferenceSize = .zero
//            $0.footerReferenceSize = .zero
//            $0.minimumLineSpacing = lineSpace
//            $0.minimumInteritemSpacing = interitemSpace
//            $0.sectionInset = inset
//            $0.scrollDirection = .vertical
//            $0.itemSize = CGSize(cellWidth, cellWidth)
//        }
        
        return self
    }
    
}
